namespace Delphi.Mimir.Migrations
{
    using System;
    using System.Data.Entity.Migrations;
    
    public partial class AddPortfolios : DbMigration
    {
        public override void Up()
        {
            CreateTable(
                "fin.pfm_accounts",
                c => new
                    {
                        act_id = c.Int(nullable: false, identity: true),
                        act_prt_id = c.Int(nullable: false),
                        act_cur_id = c.Int(nullable: false),
                    })
                .PrimaryKey(t => t.act_id)
                .ForeignKey("fin.com_currencies", t => t.act_cur_id, cascadeDelete: true)
                .ForeignKey("fin.pfm_portfolios", t => t.act_prt_id, cascadeDelete: true)
                .Index(t => t.act_prt_id)
                .Index(t => t.act_cur_id);
            
            CreateTable(
                "fin.pfm_portfolios",
                c => new
                    {
                        prt_id = c.Int(nullable: false, identity: true),
                        prt_clt_id = c.Int(nullable: false),
                        prt_name = c.String(nullable: false, maxLength: 250, unicode: false),
                        prt_cur_id = c.Int(nullable: false),
                    })
                .PrimaryKey(t => t.prt_id)
                .ForeignKey("fin.pfm_clients", t => t.prt_clt_id, cascadeDelete: true)
                .ForeignKey("fin.com_currencies", t => t.prt_cur_id)
                .Index(t => t.prt_clt_id)
                .Index(t => t.prt_cur_id);
            
            CreateTable(
                "fin.pfm_clients",
                c => new
                    {
                        clt_id = c.Int(nullable: false, identity: true),
                        clt_first_name = c.String(nullable: false, maxLength: 250, unicode: false),
                        clt_family_name = c.String(nullable: false, maxLength: 250, unicode: false),
                    })
                .PrimaryKey(t => t.clt_id);
            
            CreateTable(
                "fin.pfm_transactions",
                c => new
                    {
                        trn_id = c.Int(nullable: false, identity: true),
                        trn_act_id = c.Int(nullable: false),
                        trn_sym_id = c.Int(),
                        trn_cur_id = c.Int(nullable: false),
                        trn_order_ts = c.DateTime(nullable: false),
                        trn_exec_ts = c.DateTime(),
                        trn_units = c.Decimal(precision: 18, scale: 6),
                        trn_amount = c.Decimal(nullable: false, precision: 18, scale: 6),
                        trn_fees = c.Decimal(nullable: false, precision: 18, scale: 6),
                        trn_amount_ref_cur = c.Decimal(nullable: false, precision: 18, scale: 6),
                        trn_fees_ref_cur = c.Decimal(nullable: false, precision: 18, scale: 6),
                    })
                .PrimaryKey(t => t.trn_id)
                .ForeignKey("fin.pfm_accounts", t => t.trn_act_id, cascadeDelete: true)
                .ForeignKey("fin.com_currencies", t => t.trn_cur_id)
                .ForeignKey("fin.eod_symbols", t => t.trn_sym_id)
                .Index(t => t.trn_act_id, name: "IX_TRN")
                .Index(t => t.trn_sym_id)
                .Index(t => t.trn_cur_id);
            
        }
        
        public override void Down()
        {
            DropForeignKey("fin.pfm_transactions", "trn_sym_id", "fin.eod_symbols");
            DropForeignKey("fin.pfm_transactions", "trn_cur_id", "fin.com_currencies");
            DropForeignKey("fin.pfm_transactions", "trn_act_id", "fin.pfm_accounts");
            DropForeignKey("fin.pfm_portfolios", "prt_cur_id", "fin.com_currencies");
            DropForeignKey("fin.pfm_portfolios", "prt_clt_id", "fin.pfm_clients");
            DropForeignKey("fin.pfm_accounts", "act_prt_id", "fin.pfm_portfolios");
            DropForeignKey("fin.pfm_accounts", "act_cur_id", "fin.com_currencies");
            DropIndex("fin.pfm_transactions", new[] { "trn_cur_id" });
            DropIndex("fin.pfm_transactions", new[] { "trn_sym_id" });
            DropIndex("fin.pfm_transactions", "IX_TRN");
            DropIndex("fin.pfm_portfolios", new[] { "prt_cur_id" });
            DropIndex("fin.pfm_portfolios", new[] { "prt_clt_id" });
            DropIndex("fin.pfm_accounts", new[] { "act_cur_id" });
            DropIndex("fin.pfm_accounts", new[] { "act_prt_id" });
            DropTable("fin.pfm_transactions");
            DropTable("fin.pfm_clients");
            DropTable("fin.pfm_portfolios");
            DropTable("fin.pfm_accounts");
        }
    }
}
